local zhengyan = fk.CreateSkill {
  name = "lvshi__zhengyan",
}

Fk:loadTranslationTable{
  ["lvshi__zhengyan"] = "铮言",
  [":lvshi__zhengyan"] = "你使用【桃】或装备牌可选择其他角色为目标；当你使用牌结算后，若之目标包括己方角色，你可弃置一名其他角色的一张牌。",
  ["#lvshi__zhengyan-active"] = "你可以选择【桃】或装备牌和一名其他角色",
  ["#lvshi__zhengyan-choose"] = "铮言：你可弃置一名其他角色的一张牌",
  ["$lvshi__zhengyan1"] = "陛下若此，天下何以观之！",
  ["$lvshi__zhengyan2"] = "偏听谄谀之言，此为万民所仰之君乎？",
  ["$lvshi__zhengyan3"] = "陛下欲复昔日桓公之事乎？",
}

local ls = require "packages/lvshi/utility"

zhengyan:addEffect("active", {
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#lvshi__zhengyan-active",
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and (Fk:getCardById(to_select).type == Card.TypeEquip or Fk:getCardById(to_select).trueName == "peach")
    and table.contains(player:getHandlyIds(), to_select)
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and #selected_cards == 1 and to_select ~= player and
    (Fk:getCardById(selected_cards[1]).type == Card.TypeEquip or to_select:isWounded())
    and not player:isProhibited(to_select, Fk:getCardById(selected_cards[1]))
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local card = Fk:getCardById(effect.cards[1])
    if not player:isProhibited(target, card) then
      room:useCard({
        card = card,
        from = player,
        tos = { target },
        skillName = zhengyan.name,
      })
    end
  end,
})

zhengyan:addEffect(fk.CardUseFinished, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhengyan.name) and data.tos and
      table.find(data.tos, function(p) return ls.isFriend(player, p) end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = table.filter(room:getOtherPlayers(player), function (p) return not p:isNude() end),
      min_num = 1,
      max_num = 1,
      skill_name = zhengyan.name,
      cancelable = true,
      prompt = "#lvshi__zhengyan-choose",
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    if not to:isNude() then
      local id = room:askToChooseCard(player, {
        target = to,
        flag = "he",
        skill_name = zhengyan.name,
      })
      room:throwCard(id, zhengyan.name, to, player)
    end
  end,
})

return zhengyan